//
//  ContractEquipmentListViewController.m
//  EPBPro
//
//  Created by wucha on 2018/7/9.
//  Copyright © 2018年 fc. All rights reserved.
//

#import "ContractEquipmentListViewController.h"
#import "BaseActionInfo.h"
#import "MachineTableViewCell.h"
#import "EquipmentInfo.h"
#import "MachineDetailViewController.h"
#import "ContractEquipmentActionInfo.h"

@interface ContractEquipmentListViewController ()
@property (nonatomic,strong) NSString *contractId;

@end

@implementation ContractEquipmentListViewController

-(id)initWithContractId:(NSString*)contractId{
    if (self == [super init]) {
        self.contractId = contractId;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.titleName = @"设备列表";
    self.tableView.separatorStyle = 0;
    [self loadData];
    
}

-(void)loadData{
    __weak ContractEquipmentListViewController *filterView = self;
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [filterView loadHeader];
    }];
    header.lastUpdatedTimeLabel.hidden = YES;
    self.tableView.mj_header = header;
    
    [self.tableView.mj_header beginRefreshing];
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadFooter)];
    
    ContractEquipmentActionInfo *contractActionInfo = [[ContractEquipmentActionInfo alloc] init];
    contractActionInfo.contactId = self.contractId;
    contractActionInfo.offset = 0;
    contractActionInfo.limit = 10;
//    equipmentActionInfo.status = self.status;
//    equipmentActionInfo.city = self.areaInfo.name;
    [self setClass:@"HttpContractAction" action:@selector(postContractEquipmentList:block:) object:contractActionInfo];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.resultArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    MachineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[MachineTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell...
    EquipmentInfo *equipmentInfo = self.resultArray[indexPath.row];
    [cell setMachineInfo:equipmentInfo];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    EquipmentInfo *equipmentInfo = self.resultArray[indexPath.row];
    MachineDetailViewController *machineDetailViewController = [[MachineDetailViewController alloc] initWithEquipmentInfo:equipmentInfo];
    [self.navigationController pushViewController:machineDetailViewController animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
